import absunitPkg from './basegraphunit.js'
import coorPkg from '../../struct/coord.js'
import globalConst from '../../globalConst.js';
import { GlobalVar } from '../../globalvar.js';

class TextInfo extends absunitPkg.BaseGraphUnit {
    constructor() {
        super();
        this.sFormatContent = "";//格式化后，只有一行的文本内容
        this.sOrigContent = "";//原始文本內容，可以帶換行符
        this.ycKind = "";//遥测通道名称，普通文本和设备标签，本字段无效并且为空

        this.x = 0;//文本中心坐标点
        this.y = 0;
        this.fontsize = GlobalVar.fontInfo.fontsize;
        this.linespace = GlobalVar.fontInfo.linedspace;        // 行间距
        this.fontFamily = GlobalVar.fontInfo.fontFamily;
        this.bold = GlobalVar.fontInfo.bold;			  // 粗体
        this.italic = GlobalVar.fontInfo.italic;		  // 倾斜
        this.underline = GlobalVar.fontInfo.underline;	  // 带下划线
        this.strikeout = GlobalVar.fontInfo.fontStrikeout;	  // 中间有直线通过的文本
        
        this.backColor = GlobalVar.fontInfo.fontBKColor.toValue(); //文本底纹颜色，RGBA
        //0--默认，不使用文本底纹，此时backColor无效；非0，使用backColor做文本背景色
        this.useBKFlag = GlobalVar.fontInfo.useBKFlag;

        this.labelkind = 0;//0,普通文本;1,设备名称标签；
        this.alignTypeH = 'mid';//水平对齐方式
        this.alignTypeV = 'mid';//垂直对齐方式
        
        this.pos = new coorPkg.PointPos();
        this.type = globalConst.GlobalConst.BaseUnitText;
        this.type = this.type <<16;
        this.color = GlobalVar.fontInfo.fontColor.toValue();
        this.isDimText = false;
        this.isTitleFlag = false;

        this.parentGID = 0;//文本标签所属图形ID
        this.width = 120;//文本输入框尺寸
        this.height = 16;
        this.lineMode = 0;
    }

    translateSubInfo(tx,ty){
        this.x += tx;
        this.y += ty;
    }

    toJson() {
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["sFormatContent"] = this.sFormatContent;
        jsonobj["sOrigContent"] = this.sOrigContent;
        jsonobj["ycKind"] = this.ycKind;
        jsonobj["x"] = this.x;
        jsonobj["y"] = this.y;
        this.pos.x = this.x;
        this.pos.y = this.y;
        jsonobj["fontsize"] = this.fontsize;
        jsonobj["linespace"] = this.linespace;      
        jsonobj["fontFamily"] = this.fontFamily;
        jsonobj["bold"] = this.bold;		
        jsonobj["italic"] = this.italic;		
        jsonobj["underline"] = this.underline;	
        jsonobj["strikeout"] = this.strikeout;	 
        jsonobj["labelkind"] = this.labelkind;
        jsonobj["alignTypeH"] = this.alignTypeH;
        jsonobj["alignTypeV"] = this.alignTypeV;

        jsonobj["backColor"] = this.backColor; 
        jsonobj["useBKFlag"] = this.useBKFlag;
        jsonobj["isDimText"] = this.isDimText;
        jsonobj["isTitleFlag"] = this.isTitleFlag;
        jsonobj["parentGID"] = this.parentGID;
        jsonobj["width"] = this.width;
        jsonobj["height"] = this.height;
        return jsonobj;
    }
    fromJson(jsonobj) {
        super.fromJson(jsonobj);
        this.sFormatContent = jsonobj["sFormatContent"];
        this.sOrigContent = jsonobj["sOrigContent"];
        this.ycKind = jsonobj["ycKind"];
        this.x = jsonobj["x"];
        this.y = jsonobj["y"];
        this.pos.x = this.x;
        this.pos.y = this.y;
        this.fontsize = jsonobj["fontsize"];
        this.linespace = jsonobj["linespace"];      
        this.fontFamily = jsonobj["fontFamily"];
        this.bold = jsonobj["bold"];		
        this.italic = jsonobj["italic"];	
        this.underline = jsonobj["underline"];
        this.strikeout = jsonobj["strikeout"]; 
        this.labelkind = jsonobj["labelkind"];
        this.alignTypeH = jsonobj["alignTypeH"];
        if (!this.alignTypeH){
            this.alignTypeH = "mid";
        }
        this.alignTypeV = jsonobj["alignTypeV"];
        if (!this.alignTypeV){
            this.alignTypeV = "mid";
        }

        this.backColor = jsonobj["backColor"];
        this.useBKFlag = jsonobj["useBKFlag"];
        this.isDimText = jsonobj["isDimText"];
        this.isTitleFlag = jsonobj["isTitleFlag"];
        this.parentGID = jsonobj["parentGID"];
        if (!this.parentGID){
            this.parentGID = 0;
        }

        this.width = jsonobj["width"];
        if (!this.width){
            this.width = 0;
        }

        this.height = jsonobj["height"];
        if (!this.height){
            this.height = 0;
        }
    }
    cloneCopy() {
        var pNewInfo = new TextInfo();
        super.cloneBaseProp(pNewInfo);
        pNewInfo.sFormatContent = this.sFormatContent;
        pNewInfo.sOrigContent = this.sOrigContent;
        pNewInfo.ycKind = this.ycKind;
        pNewInfo.x = this.x;
        pNewInfo.y = this.y;
        pNewInfo.fontsize = this.fontsize;
        pNewInfo.linespace = this.linespace;      
        pNewInfo.fontFamily = this.fontFamily;
        pNewInfo.bold = this.bold;		
        pNewInfo.italic = this.italic;	
        pNewInfo.underline = this.underline;
        pNewInfo.strikeout = this.strikeout; 
        pNewInfo.labelkind = this.labelkind;
        pNewInfo.alignTypeH = this.alignTypeH;
        pNewInfo.alignTypeV = this.alignTypeV;

        pNewInfo.backColor = this.backColor;
        pNewInfo.useBKFlag = this.useBKFlag;
        pNewInfo.setPos(this.getPos());
        pNewInfo.isDimText = this.isDimText;
        pNewInfo.isTitleFlag = this.isTitleFlag;
        pNewInfo.parentGID = this.parentGID;

        pNewInfo.width = this.width;
        pNewInfo.height = this.height;

        return pNewInfo;
    }
}

export default { TextInfo }